home *** CD-ROM | disk | FTP | other *** search
/ 3D GFX / 3D GFX.iso / pcutils / os2 / show3d / source / easy.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-31  |  20.8 KB  |  848 lines

  1. #define INCL_WIN
  2. #define INCL_GPI
  3. #define INCL_DOSMISC
  4. #define INCL_DOSPROCESS
  5. #define INCL_DEV
  6. #define INCL_SPL
  7. #define INCL_SPLDOSPRINT
  8. #define INCL_BASE
  9. #define INCL_GPIERRORS
  10.  
  11.  
  12. #include <os2.h>
  13.  
  14. #include "stdio.h"
  15. #include "string.h"
  16. #include "stdlib.h"
  17.  
  18. class Answers
  19. {   public :
  20.     enum { yes=MBID_YES, no=MBID_NO, abort=MBID_CANCEL };
  21. };
  22.  
  23. void dumplong (long n);
  24. void dump (char *s);
  25. void Warning (char *s, char *title);
  26. void Message (char *s, char *title);
  27. int Question (char *s, char *title);
  28. int QuestionAbort (char *s, char *title);
  29. void Beep (int frequency, double seconds);
  30.  
  31. enum {RUBBER_ZERO,RUBBER_START,RUBBER_CANCEL,RUBBER_DONE};
  32.  
  33. class Parameter
  34. {    MPARAM M;
  35.  
  36.     public :
  37.  
  38.     Parameter(long m) { M=(MPARAM)m; }
  39.  
  40.     Parameter(int m1, int m2) { M=MPFROM2SHORT(m1,m2); }
  41.  
  42.     Parameter(int m) { M=MPFROMSHORT(m); }
  43.  
  44.     Parameter(void *p) { M=(MPARAM)p; }
  45.  
  46.     operator MPARAM () { return M; }
  47.  
  48.     operator LONG () { return (long)M; }
  49.  
  50.     int lower () { return SHORT1FROMMP(M); }
  51.  
  52.     int higher () { return SHORT2FROMMP(M); }
  53.  
  54. };
  55.  
  56.  
  57. class Time
  58. {    double Seconds;
  59.     public :
  60.     void set ();
  61.     Time () { set(); }
  62.     double seconds () { return Seconds; }
  63.     operator double () { set(); return Seconds; }
  64.     void sleep (double t) { DosSleep(1000*t); }
  65. };
  66.  
  67. class String
  68. {    char *P;
  69.     long Size;
  70.     public :
  71.     static long defaultsize;
  72.     String ();
  73.     String (char *text, long size=defaultsize);
  74.     String (int id); // id from Resource
  75.     ~String ();
  76.     char *text () { return P; }
  77.     long size () { return Size-1; }
  78.     void copy (char *text, long size);
  79.     void copy (char *text);
  80.     char *filename ();
  81.     void stripfilename ();
  82.     operator char * () { return P; }
  83.     operator PSZ () { return P; }
  84.     int todouble (double &x);
  85.     int tolong (long &n);
  86. };
  87.  
  88. class ConvertString : public String
  89. {    public :
  90.     ConvertString (long n) : String("",32) { ltoa(n,*this,10); }
  91.     ConvertString (double x) : String("",32)
  92.         { sprintf(*this,"%-0.10g",x); }
  93. };
  94.  
  95. class Flag
  96. {    int F,Fix;
  97.     public :
  98.     Flag (int f=0) { F=f; Fix=0; }
  99.     void set () { if (Fix) return; F=1; }
  100.     void clear () { if (Fix) return; F=0; }
  101.     void toggle () { if (Fix) return; F=!F; }
  102.     operator int () { return F; }
  103.     void fix () { Fix=1; }
  104.     void unfix () { Fix=0; }
  105.     int operator = (int flag) { if (Fix) return flag; return F=flag; }
  106. };
  107.  
  108. class Rectangle
  109. {    LONG X,Y,W,H;
  110.     public :
  111.     Rectangle (LONG x=0, LONG y=0, LONG w=1, LONG h=1)
  112.     {    X=x; Y=y; W=w; H=h;
  113.     }
  114.     LONG x1 ()
  115.     {    if (W<0) return X+W+1;
  116.         else return X;
  117.     }
  118.     LONG x2 ()
  119.     {    if (W>0) return X+W-1;
  120.         else return X;
  121.     }
  122.     LONG y1 ()
  123.     {    if (H<0) return Y+H+1;
  124.         else return Y;
  125.     }
  126.     LONG y2 ()
  127.     {    if (H>0) return Y+H-1;
  128.         else return Y;
  129.     }
  130.     LONG x () { return X; }
  131.     LONG y () { return Y; }
  132.     LONG w () { return W; }
  133.     LONG h () { return H; }
  134.     void resize (LONG w, LONG h)
  135.     {    W=w; H=h;
  136.     }
  137.     void hrescale (double scale);
  138.     void wrescale (double scale);
  139.     void minsize (LONG wmin, LONG hmin);
  140. };
  141.  
  142. class Program
  143. {    HAB Hab;
  144.     HMQ Hmq;
  145.     QMSG Qmsg;
  146.     public :
  147.     Program();
  148.     ~Program();
  149.     int getmessage();
  150.     void dispatch();
  151.     void loop();
  152.     HAB hab() { return Hab; }
  153.     HMQ hmq() { return Hmq; }
  154. };
  155.  
  156. extern Program program;
  157.  
  158. class PS;
  159.  
  160. const int FCF_NORMAL=
  161.     FCF_TITLEBAR|FCF_SYSMENU|FCF_SIZEBORDER|FCF_MINMAX|
  162.     FCF_SHELLPOSITION|FCF_TASKLIST|FCF_ICON;
  163.  
  164. class Menu;
  165.  
  166. enum clicktype
  167. {     button1,button2,button3,
  168.     button1double,button2double,button3double,
  169.     button1up,button1down,
  170.     button2up,button2down,
  171.     button3up,button3down,
  172.     mousemove
  173. };
  174.  
  175. enum pointertype
  176. {    pointer_wait=SPTR_WAIT,pointer_arrow=SPTR_ARROW,
  177.     pointer_text=SPTR_TEXT,pointer_move=SPTR_MOVE
  178. };
  179.  
  180. class Window
  181. {   protected :
  182.     HWND Handle;
  183.     int Width,Height;
  184.     Flag Visible;
  185.     HPOINTER Old,New;
  186.     public :
  187.     Window ();
  188.     HWND handle () { return Handle; }
  189.     int width () { return Width; }
  190.     int height () { return Height; }
  191.     void update () { WinInvalidateRect(Handle,NULL,TRUE); }
  192.     void size (long w, long h);
  193.     void pos (long x, long y);
  194.     void validate () { WinValidateRect(Handle,NULL,TRUE); }
  195.     int visible () { return Visible; }
  196.     void setpointer (pointertype p);
  197.     void resetpointer ();
  198.     void showpointer ();
  199.     void hidepointer ();
  200.     void message (int msg, Parameter mp1=0, Parameter mp2=0)
  201.     {    WinPostMsg(Handle,msg,mp1,mp2);
  202.     }
  203.     void capture (int flag=1)
  204.     {    WinSetCapture(HWND_DESKTOP,flag?Handle:NULLHANDLE);
  205.     }
  206.     void pos (long &x, long &y, long &w, long &h);
  207.     void quit () { message(WM_CLOSE); }
  208. };
  209.  
  210. class Scroll
  211. {    public :
  212.     enum {
  213.         left=SB_LINELEFT,right=SB_LINERIGHT,
  214.         pageleft=SB_PAGELEFT,pageright=SB_PAGERIGHT,
  215.         position=SB_SLIDERPOSITION,
  216.         up=SB_LINEUP,down=SB_LINEDOWN,
  217.         pageup=SB_PAGEUP,pagedown=SB_PAGEDOWN};
  218. };
  219.  
  220. class Alignment
  221. {    public :
  222.     enum {
  223.         left=TA_LEFT,center=TA_CENTER,right=TA_RIGHT,
  224.         top=TA_TOP,middle=TA_HALF,bottom=TA_BOTTOM};
  225. };
  226.  
  227. class Keycode
  228. {    public :
  229.     enum {
  230.         up=KC_KEYUP,virtualkey=KC_VIRTUALKEY,
  231.         charkey=KC_CHAR };
  232. };
  233.  
  234. class StandardWindow : public Window
  235. {    HWND FrameHandle;
  236.     Menu *Windowmenu;
  237.     int Id;
  238.     int Rubber;
  239.     String Name;
  240.     ULONG Flags;
  241.     public :
  242.     enum {normal=FCF_NORMAL,menu=FCF_MENU,keys=FCF_ACCELTABLE,
  243.         vscrollbar=FCF_VERTSCROLL,hscrollbar=FCF_HORZSCROLL};
  244.     StandardWindow (int id,
  245.         char *name="",
  246.         ULONG flags=FCF_NORMAL);
  247.     ~StandardWindow ();
  248.     void init ();
  249.     void setmenu (Menu *m) { Windowmenu=m; }
  250.     HWND framehandle () { return FrameHandle; }
  251.     void top ();
  252.     int rubberbox (LONG x, LONG y, clicktype click,
  253.         Rectangle &R, LONG wmin=0, LONG hmin=0,
  254.         double wscale=0, double hscale=0);
  255.     virtual void redraw (PS &ps);
  256.     virtual void sized () {}
  257.     virtual void clicked (LONG x, LONG y, clicktype click) {}
  258.     virtual int key (int flags, int code, int scan) { return 0; }
  259.     void size (LONG w, LONG h);
  260.     virtual int vscrolled (int scroll, int pos) { return 0; }
  261.     virtual int hscrolled (int scroll, int pos) { return 0; }
  262.     virtual void pres_changed () { update(); }
  263.     void vscroll (int pos, int min=0, int max=100);
  264.     void hscroll (int pos, int min=0, int max=100);
  265.     friend MRESULT EXPENTRY MainWindowProc (HWND hwnd,
  266.             ULONG msg,MPARAM mp1, MPARAM mp2);
  267.     void title (char *s);
  268.     virtual int close () { return 1; }
  269.         // user tries to close the window
  270.     void starttimer (double interval, int i=1)
  271.     {    WinStartTimer(program.hab(),Handle,i,interval*1000);
  272.     }
  273.     void stoptimer (int i=1)
  274.     {    WinStopTimer(program.hab(),Handle,i);
  275.     }
  276.     virtual void timer (int i) {}
  277. };
  278.  
  279. typedef void Menuproc ();
  280.  
  281. class Menuentry
  282. {   int Command;
  283.     Menuproc *Proc;
  284.     Menuentry *Next;
  285.     public :
  286.     Menuentry (int command, Menuproc *proc,
  287.         Menuentry *next=NULL)
  288.     {    Command=command;
  289.         Proc=proc;
  290.         Next=next;
  291.     }
  292.     Menuentry *next () { return Next; }
  293.     void call (int command) { Proc(); }
  294.     int command () { return Command; }
  295. };
  296.  
  297. class Menu
  298. {   int Command;
  299.     Menuentry *Mp;
  300.     StandardWindow *W;
  301.     public :
  302.     Menu (StandardWindow &window)
  303.     {    Mp=NULL;
  304.         W=&window;
  305.         W->setmenu(this);
  306.     }
  307.     ~Menu ();
  308.     void add (ULONG command, Menuproc *proc)
  309.     {   Mp=new Menuentry(command,proc,Mp);
  310.     }
  311.     int call (int command);
  312.     int command () { return Command; }
  313.     void enable (int id, int flag);
  314.     void check (int id, int flag);
  315. };
  316.  
  317. class Rgb
  318. {    LONG Value;
  319.     public :
  320.     Rgb (int red, int green, int blue)
  321.     {    Value=((unsigned long)red<<16)+((unsigned long)green<<8)+blue;
  322.     }
  323.     Rgb (LONG value) { Value=value; }
  324.     operator LONG () { return Value; }
  325. };
  326.  
  327. class Marker
  328. {   public :
  329.     enum
  330.     {    def=MARKSYM_DEFAULT,cross=MARKSYM_CROSS,
  331.         circle=MARKSYM_SMALLCIRCLE,diamond=MARKSYM_DIAMOND,
  332.         dot=MARKSYM_DOT,square=MARKSYM_SQUARE,
  333.         plus=MARKSYM_PLUS,star=MARKSYM_EIGHTPOINTSTAR
  334.     };
  335. };
  336.  
  337. class Colors
  338. {   public :
  339.     enum
  340.     {    def=CLR_DEFAULT,white=CLR_WHITE,black=CLR_BLACK,
  341.         blue=CLR_BLUE,red=CLR_RED,pink=CLR_PINK,green=CLR_GREEN,
  342.         cyan=CLR_CYAN,yellow=CLR_YELLOW,darkgray=CLR_DARKGRAY,
  343.         darkblue=CLR_DARKBLUE,darkred=CLR_DARKRED,
  344.         darkpink=CLR_DARKPINK,darkgreen=CLR_DARKGREEN,
  345.         darkcyan=CLR_DARKCYAN,brown=CLR_BROWN,palegray=CLR_PALEGRAY,
  346.         gray=CLR_PALEGRAY,neutral=CLR_NEUTRAL
  347.     };
  348. };
  349.  
  350. class Markers
  351. {    public :
  352.     enum
  353.     {    def=MARKSYM_DEFAULT,cross=MARKSYM_CROSS,plus=MARKSYM_PLUS,
  354.         diamond=MARKSYM_DIAMOND,star=MARKSYM_SIXPOINTSTAR,
  355.         square=MARKSYM_SQUARE,solidsquare=MARKSYM_SOLIDSQUARE,
  356.         soliddiamond=MARKSYM_SOLIDDIAMOND,
  357.         sixpointstar=MARKSYM_SIXPOINTSTAR,
  358.         eightpointstart=MARKSYM_EIGHTPOINTSTAR,
  359.         dot=MARKSYM_DOT,circle=MARKSYM_SMALLCIRCLE,
  360.         blank=MARKSYM_BLANK
  361.     };
  362. };
  363.  
  364. class Font;
  365. class PS
  366. {   POINTL P;
  367.     ULONG Color,Alignment;
  368.     protected :
  369.     HPS Handle;
  370.     SIZEL S;
  371.     long X,Y;
  372.     public :
  373.     PS () : X(0),Y(0)
  374.     {    Handle=NULLHANDLE;
  375.         Color=CLR_DEFAULT; Alignment=TA_LEFT;
  376.     }
  377.     PS (HPS hps)
  378.     {    PS(); Handle=hps; GpiQueryPS(Handle,&S);
  379.     }
  380.     void clip (long x, long y, long w, long h);
  381.     void offset (long x, long y) { X=x; Y=y; }
  382.     long xoffset () { return X; }
  383.     long yoffset () { return Y; }
  384.     HPS handle () { return Handle; }
  385.     void erase () { GpiErase(Handle); }
  386.     LONG width () { return S.cx; }
  387.     LONG height () { return S.cy; }
  388.     void color (ULONG color)
  389.     {    if (Color!=color)
  390.         {    GpiSetColor(Handle,color);
  391.             Color=color;
  392.         }
  393.     }
  394.     void directcolor (int pure=0);
  395.     void setcolor (int index, Rgb rgb, int pure=0);
  396.     void defaultcolors ();
  397.     void mix (int mode) { GpiSetMix(Handle,mode); }
  398.     void move (LONG c, LONG r, ULONG color=CLR_DEFAULT);
  399.     void lineto (LONG c, LONG r, ULONG color=CLR_DEFAULT);
  400.     void linerel (LONG w, LONG h, ULONG color=CLR_DEFAULT);
  401.     void point (LONG w, LONG h, ULONG color=CLR_DEFAULT);
  402.     void text (char *s, ULONG color=CLR_DEFAULT,
  403.         ULONG alignment=TA_LEFT, ULONG valignment=TA_BASE);
  404.     void textbox (char *s, long &width, long &height);
  405.     double textextend (char *s, double vx, double vy);
  406.     void framedarea (Rectangle &R, int r, ULONG col=CLR_DEFAULT);
  407.     void frame (Rectangle &R, int r=0, ULONG color=CLR_DEFAULT);
  408.     void area (Rectangle &R, int r=0, ULONG color=CLR_DEFAULT);
  409.     void framedarea (LONG w, LONG h, int r, ULONG col=CLR_DEFAULT);
  410.     void frame (LONG w, LONG h, int r=0, ULONG color=CLR_DEFAULT);
  411.     void area (LONG w, LONG h, int r=0, ULONG color=CLR_DEFAULT);
  412.     void mark (LONG w, LONG h, ULONG type=MARKSYM_DEFAULT,
  413.         ULONG color=CLR_DEFAULT);
  414.     void circle (LONG c, LONG r, LONG rad, double factor,
  415.         ULONG col=CLR_DEFAULT);
  416.     void arc (LONG c, LONG r, LONG rad, double factor,
  417.         double phi1, double phi2,
  418.         ULONG col=CLR_DEFAULT);
  419.     void setfont (Font &font, int id=1);
  420.     void image (long w, long h, unsigned char *data);
  421. };
  422.  
  423. inline void StandardWindow::redraw (PS &ps)
  424. {    ps.erase();
  425. }
  426.  
  427. class WindowPS : public PS
  428. {   Window *W;
  429.     int getps;
  430.     void set (HPS handle, Window &window)
  431.     {    W=&window;
  432.         Handle=handle;
  433.         S.cx=window.width(); S.cy=window.height();
  434.     }
  435.     public :
  436.     WindowPS (HPS handle, Window &window)
  437.     {    set(handle,window);
  438.         getps=0;
  439.     }
  440.     WindowPS (Window &window)
  441.     {    set(WinGetPS(window.handle()),window);
  442.         getps=1;
  443.     }
  444.     ~WindowPS () { if (getps) WinReleasePS(handle()); }
  445. };
  446.  
  447. class RedrawPS : public WindowPS
  448. {    public :
  449.     RedrawPS (HWND hwnd, Window &window) :
  450.         WindowPS(WinBeginPaint(hwnd,NULLHANDLE,NULL),window) {}
  451.     ~RedrawPS () { WinEndPaint(handle()); }
  452. };
  453.  
  454. class MetafilePS : public PS
  455. {   HMF Metafilehandle;
  456.     HDC Hdc;
  457.     public :
  458.     MetafilePS (Window &window);
  459.     ~MetafilePS ();
  460.     HMF metafilehandle () { return Metafilehandle; }
  461.     void close ();
  462. };
  463.  
  464. class CopyMode
  465. {      public :
  466.     enum {
  467.         copy=ROP_SRCCOPY, or=ROP_SRCPAINT, xor=ROP_SRCINVERT,
  468.     };
  469. };
  470.  
  471. class BitmapPS : public PS
  472. {    HDC DeviceHandle;
  473.     HBITMAP BitmapHandle;
  474.     PBITMAPINFO2 Info;
  475.     int Valid,Planes,Colorbits;
  476.     public :
  477.     BitmapPS (Window &window);
  478.     BitmapPS (long w, long h);
  479.     ~BitmapPS ();
  480.     void copy (PS &ps, int mode=CopyMode::copy, long x=0, long y=0);
  481.     void save (char *filename);
  482.     HBITMAP bitmaphandle () { return BitmapHandle; }
  483. };
  484.  
  485. class Queues
  486. {    ULONG NQueues;
  487.     PRQINFO3 *Queues;
  488.     PRQINFO3 ChosenQueue;
  489.     public :
  490.     Queues (char *name="");
  491.     ~Queues () { if (Queues) delete Queues; }
  492.     ULONG number () { return NQueues; }
  493.     PRQINFO3 *chosen () { return &ChosenQueue; }
  494.     PRQINFO3 *all ();
  495. };
  496.  
  497. class PrinterPS : public PS
  498. {   HDC HandlePrinter;
  499.     DEVOPENSTRUC Dos;
  500.     String Myname;
  501.     PRQINFO3 Queue;
  502.     public :
  503.     Flag Valid,Open;
  504.     PrinterPS (char *name="Print", int op=1);
  505.     PrinterPS (Queues &q, char *name="Print", int op=1);
  506.     ~PrinterPS () { if (Open) close(); }
  507.     char *queuename () { return Dos.pszLogAddress; }
  508.     char *drivername () { return Dos.pszDriverName; }
  509.     void open ();
  510.     void close ();
  511. };
  512.  
  513. class Bitmap
  514. {    HBITMAP Handle;
  515.     HDC DeviceHandle;
  516.     HPS PsHandle;
  517.     SIZEL S;
  518.     public :
  519.     Bitmap (int id, int width=0, int height=0);
  520.     ~Bitmap ();
  521.     HBITMAP handle () { return Handle; }
  522. };
  523.  
  524. class Help
  525. {   HWND Handle;
  526.     Help *H;
  527.     Flag Valid;
  528.     public :
  529.     Help (StandardWindow &window,
  530.         int id, char *filename, char *title="");
  531.     void Help::general (void)
  532.     {    if (Valid) WinSendMsg(Handle,HM_EXT_HELP,NULL,NULL);
  533.     }
  534.     void Help::index (void)
  535.     {    if (Valid) WinSendMsg(Handle,HM_HELP_INDEX,NULL,NULL);
  536.     }
  537.     void Help::content (void)
  538.     {   if (Valid) WinSendMsg(Handle,HM_HELP_CONTENTS,NULL,NULL);
  539.     }
  540.     void Help::display (int id)
  541.     {    if (Valid) WinSendMsg(Handle,HM_DISPLAY_HELP,
  542.             MPFROMSHORT(id),HM_RESOURCEID);
  543.     }
  544.     int valid () { return Valid; }
  545. };
  546.  
  547.  
  548. class Thread
  549.  
  550. {    int (*F) (Parameter);
  551.     TID Tid;
  552.     int Started,Expected;
  553.     long Stacksize;
  554.     Parameter P;
  555.     public :
  556.     Thread (int (*f) (Parameter), long stacksize=4096) : P(0)
  557.     {    F=f;
  558.         Started=0; Stacksize=stacksize;
  559.         Expected=0;
  560.     }
  561.     void start (Parameter p=0);
  562.     void stop ();
  563.     void suspend ();
  564.     void resume ();
  565.     void wait ();
  566.     int expected () { return Expected; }
  567.     Parameter p () { return P; }
  568.     int call () { return F(P); }
  569.     int started () { return Started; }
  570.     void finished () { Started=0; }
  571. };
  572.  
  573. class Dialogitem;
  574.  
  575.  
  576. class Dialog
  577.  
  578. {    HWND Handle;
  579.  
  580.     int Result,Id;
  581.  
  582.     Window *W;
  583.  
  584.     String S;
  585.  
  586.     Dialogitem *Items;
  587.  
  588.     Help *H;
  589.  
  590.     int Hid;
  591.  
  592.     void init (Window &window, int id);
  593.  
  594.     Dialog *Next;
  595.  
  596.     public :
  597.  
  598.     enum { ok=DID_OK,cancel=DID_CANCEL };
  599.  
  600.     Dialog (Window &window, int id);
  601.  
  602.     Dialog (Window &window, int id, Help &h, int hid);
  603.  
  604.     Dialogitem *entry (Dialogitem *item);
  605.  
  606.     void carryout ();
  607.  
  608.     void show ();
  609.  
  610.     virtual void start () {}
  611.  
  612.     virtual void stop () {}
  613.  
  614.     virtual int handler (int command) { return 1; }
  615.  
  616.     int result () { return Result; }
  617.  
  618.     char *gettext (int id, char *text, long size=String::defaultsize);
  619.  
  620.     char *gettext (int id);
  621.  
  622.     void settext (int id, char *text);
  623.  
  624.     MRESULT message (int id, int msg,
  625.  
  626.         Parameter mp1=NULL, Parameter mp2=NULL);
  627.  
  628.     HWND handle () { return Handle; }
  629.  
  630.     friend MRESULT EXPENTRY dialogproc (HWND hwnd, ULONG msg,
  631.  
  632.         MPARAM mp1, MPARAM mp2);
  633.     void finish ()
  634.     {    WinSendMsg(Handle,WM_COMMAND,MPARAM(DID_OK),0);
  635.     }
  636.     virtual int key (int flags, int code, int scan) { return 0; }
  637.     Window *w () { return W; }
  638. };
  639.  
  640.  
  641. class Dialogitem
  642.  
  643. {    Dialogitem *Next;
  644.  
  645.     protected :
  646.  
  647.     int Id;
  648.  
  649.     Dialog *D;
  650.  
  651.     public :
  652.  
  653.     Dialogitem (int id, Dialog &dialog);
  654.  
  655.     Dialogitem *next () { return Next; }
  656.  
  657.     int id () { return Id; }
  658.  
  659.     virtual void init () {}
  660.  
  661.     virtual void exit () {}
  662.  
  663.     virtual void command (Parameter mp1,Parameter mp2) {}
  664.  
  665.     virtual void notify () {}
  666.  
  667.     void finish () { D->finish(); }
  668.  
  669. };
  670.  
  671.  
  672. class CheckItem : public Dialogitem
  673.  
  674. {    int F;
  675.  
  676.     public :
  677.  
  678.     CheckItem (int id, Dialog &dialog, int flag)
  679.  
  680.         : Dialogitem(id,dialog) { F=flag; }
  681.  
  682.     virtual void init ();
  683.  
  684.     virtual void exit ();
  685.  
  686.     void set (int f) { F=f; }
  687.  
  688.     void reinit (int f) { set(f); init(); }
  689.  
  690.     operator int () { return F; }
  691.  
  692. };
  693.  
  694.  
  695. class RadioItem : public Dialogitem
  696.  
  697. {    int I,N,*Ids;
  698.  
  699.     public :
  700.  
  701.     RadioItem (int *ids, int n, Dialog &dialog, int i=1)
  702.  
  703.         : Dialogitem(0,dialog),N(n),I(i),Ids(ids) {}
  704.  
  705.     virtual void init();
  706.  
  707.     virtual void exit ();
  708.  
  709.     void set (int i) { I=i; }
  710.  
  711.     void reinit (int i) { set(i); init(); }
  712.  
  713.     operator int () { return I; }
  714.  
  715. };
  716.  
  717.  
  718. class StringItem : public Dialogitem
  719.  
  720. {   String S;
  721.  
  722.     int Length;
  723.  
  724.     Flag Readonly;
  725.  
  726.     public :
  727.  
  728.     StringItem (int id, Dialog &dialog, char *string, int length=64)
  729.  
  730.         : Dialogitem(id,dialog),S(string) { Length=length; }
  731.  
  732.     virtual void init ();
  733.  
  734.     virtual void exit ();
  735.  
  736.     void set (char *text) { S.copy(text); }
  737.  
  738.     void reinit (char *text) { set(text); init(); }
  739.  
  740.     void limit (int length);
  741.  
  742.     void readonly (int flag=1) { Readonly=flag; }
  743.  
  744.     operator char * () { return S; }
  745.  
  746. };
  747.  
  748.  
  749.  
  750. class DoubleItem : public Dialogitem
  751.  
  752. {   double X;
  753.  
  754.     String S;
  755.  
  756.     Flag Readonly;
  757.  
  758.     public :
  759.  
  760.     DoubleItem (int id, Dialog &dialog, double x)
  761.  
  762.         : Dialogitem(id,dialog),S("",64) { X=x; }
  763.  
  764.     virtual void init ();
  765.  
  766.     virtual void exit ();
  767.  
  768.     void set (double x) { X=x; }
  769.  
  770.     void reinit (double x) { set(x); init(); }
  771.  
  772.     void readonly (int flag=1) { Readonly=flag; }
  773.  
  774.     operator double () { return X; }
  775.  
  776. };
  777.  
  778.  
  779. class LongItem : public Dialogitem
  780.  
  781. {   long N;
  782.  
  783.     String S;
  784.  
  785.     Flag Readonly;
  786.  
  787.     public :
  788.  
  789.     LongItem (int id, Dialog &dialog, long n)
  790.  
  791.         : Dialogitem(id,dialog),S("",64) { N=n; }
  792.  
  793.     virtual void init ();
  794.  
  795.     virtual void exit ();
  796.  
  797.     void set (long n) { N=n; }
  798.  
  799.     void reinit (long n) { set(n); init(); }
  800.  
  801.     void readonly (int flag=1) { Readonly=flag; }
  802.  
  803.     operator long () { return N; }
  804.  
  805. };
  806.  
  807.  
  808. class SpinItem : public Dialogitem
  809.  
  810. {   long N,Lower,Upper;
  811.  
  812.     String S;
  813.  
  814.     public :
  815.  
  816.     SpinItem (int id, Dialog &dialog, long n,
  817.  
  818.         long lower, long upper)
  819.  
  820.         : Dialogitem(id,dialog),S("",64)
  821.  
  822.     {    N=n; Lower=lower; Upper=upper;
  823.  
  824.     }
  825.  
  826.     virtual void init ();
  827.  
  828.     virtual void exit ();
  829.  
  830.     void set (long n, long lower, long upper)
  831.  
  832.     {    N=n; Lower=lower; Upper=upper; }
  833.  
  834.     void reinit (long n, long lower, long upper)
  835.  
  836.     {    set(n,lower,upper); init();
  837.  
  838.     }
  839.  
  840.     void set (long n) { N=n; }
  841.  
  842.     void reinit (long n) { set(n); init(); }
  843.  
  844.     operator long () { return N; }
  845.  
  846. };
  847.  
  848.  
  849. class SliderItem : public Dialogitem
  850.  
  851. {   long N;
  852.  
  853.     String S;
  854.  
  855.     public :
  856.  
  857.     SliderItem (int id, Dialog &dialog, long n)
  858.  
  859.         : Dialogitem(id,dialog),S("",64)
  860.  
  861.     {    N=n;
  862.  
  863.     }
  864.  
  865.     virtual void init ();
  866.  
  867.     virtual void exit ();
  868.  
  869.     void set (long n)
  870.  
  871.     {    N=n; }
  872.  
  873.     void reinit (long n)
  874.  
  875.     {    set(n); init();
  876.  
  877.     }
  878.  
  879.     void tick (int n, int size=3);
  880.  
  881.     void label (int n, char *text);
  882.  
  883.     operator long () { return N; }
  884.  
  885. };
  886.  
  887.  
  888. class ValuesetItem : public Dialogitem
  889.  
  890. {    int Col,Row;
  891.  
  892.     public :
  893.  
  894.     ValuesetItem (int id, Dialog &dialog, int r=1, int c=1)
  895.  
  896.         : Dialogitem(id,dialog),Col(c),Row(r) {}
  897.  
  898.     void select (int row, int col);
  899.  
  900.     void setbitmap (int row, int col, Bitmap &b);
  901.  
  902.     void setcolor (int row, int col, long color);
  903.  
  904.     virtual void init () { select(Row,Col); }
  905.  
  906.     virtual void exit ();
  907.  
  908.     virtual void command (Parameter mp1, Parameter mp2);
  909.  
  910.     int col () { return Col; }
  911.  
  912.     int row () { return Row; }
  913.  
  914. };
  915.  
  916.  
  917. class ListItem : public Dialogitem
  918.  
  919. {   int Selection;
  920.  
  921.     public :
  922.  
  923.     ListItem (int id, Dialog &dialog)
  924.  
  925.         : Dialogitem(id,dialog) {}
  926.  
  927.     void select (int sel);
  928.  
  929.     virtual void init () { select(0); }
  930.  
  931.     virtual void exit ();
  932.  
  933.     virtual void command (Parameter mp1, Parameter mp2);
  934.  
  935.     void insert (char *text);
  936.  
  937.     operator int () { return Selection; }
  938.  
  939. };
  940.  
  941.  
  942. class MultilineItem : public Dialogitem
  943.  
  944. {   String S;
  945.  
  946.     Flag Readonly;
  947.  
  948.     public :
  949.  
  950.     MultilineItem (int id, Dialog &dialog, char *string,
  951.  
  952.             int length=1024)
  953.  
  954.         : Dialogitem(id,dialog),S(string,length) {}
  955.  
  956.     virtual void init ();
  957.  
  958.     virtual void exit ();
  959.  
  960.     void set (char *text) { S.copy(text); }
  961.  
  962.     void reinit (char *text) { set(text); init(); }
  963.  
  964.     void limit (int length);
  965.  
  966.     void readonly (int flag=1) { Readonly=flag; }
  967.  
  968.     operator char * () { return S; }
  969.  
  970. };
  971.  
  972.  
  973.  
  974. class FileSelector
  975.  
  976. {    int Freturn;
  977.  
  978.     Window *W;
  979.  
  980.     FILEDLG Fd;
  981.  
  982.     String Filter,Title,Ok;
  983.  
  984.     public :
  985.  
  986.     FileSelector(Window &window,
  987.  
  988.         char *filter, int saving,
  989.  
  990.         char *title="", char *ok=0);
  991.  
  992.     char *select ();
  993.  
  994. };
  995.  
  996.  
  997. class FontSelector
  998.  
  999. {   FONTDLG Fd;
  1000.  
  1001.     String Facename;
  1002.  
  1003.     int Codepage,Type,Result;
  1004.  
  1005.     double Pointsize;
  1006.  
  1007.     public :
  1008.  
  1009.     enum { screen, printer };
  1010.  
  1011.     FontSelector (int type=screen,
  1012.  
  1013.         char *name="", double pointsize=10, int codepage=0)
  1014.  
  1015.         : Type(type),Facename(name,66),Pointsize(pointsize),
  1016.  
  1017.             Codepage(codepage),Result(DID_CANCEL) {}
  1018.  
  1019.     int select (Window &window);
  1020.  
  1021.     FATTRS *fat () { return &Fd.fAttrs; }
  1022.  
  1023.     FONTDLG *fd () { return &Fd; }
  1024.  
  1025.     operator int () { return Result; }
  1026.  
  1027. };
  1028.  
  1029.  
  1030. class Fonts
  1031.  
  1032. {    long Count;
  1033.     FONTMETRICS *AllFonts;
  1034.     public :
  1035.     Fonts (PS &ps);
  1036.     ~Fonts ();
  1037.     long count () { return Count; }
  1038.     FONTMETRICS *fonts () { return AllFonts; }
  1039. };
  1040.  
  1041. class Font
  1042. {    FATTRS Fat;
  1043.     double NominalPointSize,PointSize;
  1044.     public :
  1045.     Font (FontSelector &fs);
  1046.     FATTRS *fat () { return &Fat; }
  1047.     char *name () { return Fat.szFacename; }
  1048.     double nominalsize () { return NominalPointSize; }
  1049.     double pointsize () { return PointSize; }
  1050. };
  1051.  
  1052. class Profile
  1053. {    int P;
  1054.     String S,H;
  1055.     public :
  1056.     enum { user=HINI_USERPROFILE,system=HINI_SYSTEMPROFILE };
  1057.     Profile (char *prog, int p=user) : P(p),S(prog),H("") {}
  1058.     void write (char *k, void *p, unsigned long size)
  1059.     {    PrfWriteProfileData(P,S,k,p,size);
  1060.     }
  1061.     void writestring (char *k, char *i);
  1062.     void writedouble (char *k, double x);
  1063.     void writelong (char *k, long x);
  1064.     void writeint (char *k, int x);
  1065.     int read (char *k, void *p, unsigned long size)
  1066.     {    return PrfQueryProfileData(P,S,k,p,&size);
  1067.     }
  1068.     char *readstring (char *k, char *d="", long size=String::defaultsize);
  1069.     double readdouble (char *k, double x=0);
  1070.     long readlong (char *k, long x=0);
  1071.     int readint (char *k, int x=0);
  1072. };
  1073.  
  1074. class Clipboard
  1075.  
  1076. {    public :
  1077.  
  1078.     void copy (MetafilePS &meta);
  1079.  
  1080. };
  1081.  
  1082.  
  1083.